// 登录业务
const btnlogin = document.querySelector('#btn-login')
const form = document.querySelector('.login-form')
btnlogin.addEventListener('click', async function () {
    const data = serialize(form, { hash: true, empty: true })
    // console.log(data);
    const { username, password } = data
    // console.log(username);

    if (username.length > 8 && username.length < 30) {

    } else {
        return showToast('请输入8-30位账号')
    }
    if (password.length > 6 && password.length < 30) {

    } else {
        return showToast('请输入6-30位密码')
    }
    try {
        const { message, data: { token } } = await axios.post('/login', data)
        showToast(message)
        location.href = 'index.html'
        localStorage.setItem('name', username)
        localStorage.setItem('token', token)
    } catch (err) {
        console.log(err);
    }
})

